package controller;

import service.UserService;
import util.MySpring;
import service.AtmService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Login extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name2 = req.getParameter("name");
        String password = req.getParameter("password");
//        AtmService atmService = MySpring.getBean("service.AtmService");
//        String login = atmService.login(name2, password);
        UserService service = MySpring.getBean("service.UserService");
        String login = service.login(name2,password);
        if ("成功".equals(login)){
             req.getRequestDispatcher("welcome.jsp").forward(req,resp);
//             req.getRequestDispatcher("wel.jsp").forward(req,resp);
//             resp.sendRedirect("wel2.jsp");
        }else{
//            req.getRequestDispatcher("index.html").forward(req,resp);
            req.setAttribute("result",login);
            req.getRequestDispatcher("index1.jsp").forward(req,resp);
        }
    }
}
